using CustomCharacter.Ability;
using Exiled.API.Enums;
using HarmonyLib;
using MEC;
using RemoteAdmin;
using RgCore.Modules;
using CustomCharacter.Commands;
using CustomCharacter.Commands.AbilityManagerCommands;
using CustomCharacter.Commands.CustomCharacterCommands;
using RgCore.Modules.Commands.SubPluginManagerCommands;

namespace CustomCharacter
{
    public class CustomCharacterPlugin : RgPlugin
    {
        public override string Name => "自定义角色";
        public override string Id => "CustomCharacter";
        public override PluginPriority Priority => PluginPriority.Highest;
        public override bool CanUnload => false;
        public static CustomCharacterPlugin instance = null;
        public Harmony HarmonyPatch { get; private set; }
        public SubPluginManager<RoleInfoAttribute> Manager { get; private set; }
        public SubPluginManagerCommand<RoleInfoAttribute> Command { get; private set; }

        public override void OnEnabled()
        {
            instance = this;
            Manager = new SubPluginManager<RoleInfoAttribute>(Name, "CustomCharacters", typeof(CustomCharacter));
            Manager.LoadObjects();
            Command = new SubPluginManagerCommand<RoleInfoAttribute>("rm", Manager);
            CommandProcessor.RemoteAdminCommandHandler.RegisterCommand(Command);
            CommandProcessor.RemoteAdminCommandHandler.RegisterCommand(new AbilityManagerCommand());
            CommandProcessor.RemoteAdminCommandHandler.RegisterCommand(new CustomCharacterCommand());
            CommandProcessor.RemoteAdminCommandHandler.RegisterCommand(new VoiceChannelCommand());
            QueryProcessor.DotCommandHandler.RegisterCommand(new AbilityCommand());
            CustomCharacter.Coroutine = Timing.RunCoroutine(CustomCharacter.Update());
            CustomCharacter.AbilityCoroutine = Timing.RunCoroutine(AbilityManager.Update());
            HarmonyPatch = new Harmony(Id);
            HarmonyPatch.PatchAll();
            CustomCharacter.SetEnabled();
        }
    }
}